package com.shijie.controller;

import com.shijie.dto.PoolAddDTO;
import com.shijie.dto.PoolUpdateDTO;
import com.shijie.entity.Pool;
import com.shijie.result.SjResult;
import com.shijie.service.PoolService;
import com.shijie.vo.JudgePoolVO;
import com.shijie.vo.PoolVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequiredArgsConstructor
public class PoolController {

    private final PoolService poolService;

    @GetMapping("/list")
    public SjResult<List<PoolVO>> list() {

        List<PoolVO> poolVOs = poolService.list();

        return SjResult.success(poolVOs);
    }

    @GetMapping("/get/{poolId}")
    public SjResult<PoolVO> getByPoolId(@PathVariable("poolId") Long poolId) {
        PoolVO poolVO = poolService.getByPoolId(poolId);

        return SjResult.success(poolVO);
    }

    @PostMapping("/save")
    public SjResult<Void> save(@RequestBody PoolAddDTO poolAddDTO) {
        log.info("poolAddDTO:{}", poolAddDTO);

        boolean ok = poolService.save(poolAddDTO);

        return SjResult.success();
    }

    @PutMapping("/update")
    public SjResult<Void> update(@RequestBody PoolUpdateDTO poolUpdateDTO) {
        boolean ok = poolService.update(poolUpdateDTO);
        return SjResult.success();
    }

    @DeleteMapping("/delete/{poolId}")
    public SjResult<Void> delete(@PathVariable("poolId") Long poolId) {
        boolean ok = poolService.delete(poolId);
        return SjResult.success();
    }

    @GetMapping("/judgeRequire")
    public SjResult<JudgePoolVO> getJudgeRequire(Long poolId) {
        JudgePoolVO judgePoolVO = poolService.getJudgeRequire(poolId);
        log.warn("JudgePoolVO: {}", judgePoolVO);
        return SjResult.success(judgePoolVO);
    }

}
